package com.example.lib_base.event;

import com.kunminx.architecture.ui.callback.ProtectedUnPeekLiveData;
import com.kunminx.architecture.ui.callback.UnPeekLiveData;

import androidx.lifecycle.ViewModel;

public class ShareViewModel extends ViewModel {
    //防止数据倒灌的LiveData  作为全局通信数据源 github上有多个LiveDataBus
    //关闭页面监听
    private final UnPeekLiveData<Boolean> toCloseActivityIfAllowed = new UnPeekLiveData<>();
    private final UnPeekLiveData<Double> temp = new UnPeekLiveData<>();
    private final UnPeekLiveData<Double> humidity = new UnPeekLiveData<>();

    //message 提醒消息设置
    public final UnPeekLiveData<Long> messageRemind = new UnPeekLiveData<>();
    //已更变数据 变更提醒
    public final UnPeekLiveData<Boolean> hasChangedRemind = new UnPeekLiveData<>();

    public ProtectedUnPeekLiveData<Boolean> isToCloseActivityIfAllowed() {
        return toCloseActivityIfAllowed;
    }

    public void requestToCloseActivityIfAllowed(boolean allow) {
        toCloseActivityIfAllowed.setValue(allow);
    }


    /**
     * 设置返回
     * 0 温度
     * 1 湿度
     * @param type
     * @return
     */
    public ProtectedUnPeekLiveData<Double> getTempOrHumidity(int type){
        if (type == 0){
            return temp;
        }else {
            return humidity;
        }
    }

    public void setTemp(Double temp){
        this.temp.setValue(temp);
    }
    public void setHumidity(Double humidity){
        this.humidity.setValue(humidity);
    }
}
